home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dirut
/
new17.zip
/
NEW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-17
|
17KB
|
617 lines
/* NEW.C (V1.7) -- Written by Scott R. Houck 17 Feb 89
*
* Directory listing of files since or before a certain number of days.
*
* Modelled after Jay Jervey's utility. My version lists the file
* information in the standard DOS directory listing format (except that
* I am also showing the seconds in the file time), adds some features
* (/p, /s and /e), and corrects some errors in Jervey's utility. Julian
* date calculations were adapted from James Seed's c_dates library.
*
* Compiled with MSC version 5.1. Uses PforCe functions drfullpath() and
* vidcsrtyp().
*
* The syntax is: NEW [filespec [filespec...]] [options]
*
* Options and filespec can be in any order. Valid options are:
*
* /h Show help screen
* /? Same as /h
* /n Show files SINCE the number of days specified by n
* /-n Show files BEFORE the number of days specified by n
* /p Pause when screen display is full
* /s Search specified directory and its subdirectories
* /e Search entire disk
* /d Include directories in listing
* /do Include directories ONLY in listing
* /j Junk option -- include files with corrupted dates
* /i Ignore the environment variable NEW if it is defined
*
* If filespec is omitted, *.* is assumed. Also, a "day" in this program
* starts at 6:00 am and ends at 5:59 am the following day.
*
* Compile with: cl -AL new.c pfms3l.lib /link /st:40000 /e
*
* Version 1.3 handles file dates where year > 99 (corrupted filestamps).
* Version 1.4 will not display files whose date and time are greater than
* the current date and time unless the /J (junk) option is chosen.
* Also added /D to include directories in listing.
* Version 1.5 checks the number of text rows available so that the pause
* option (/P) pauses at the correct place.
* Version 1.6 allows multiple filespecs and is handy for specifying
* multiple drives to be searched with the /e option. For example,
* NEW c: d: /e.
* Version 1.7 checks for an environment variable named NEW to find
* default options and/or filespecs. If it is defined, but you want
* NEW to ignore the environment variable, you may specify /I (for
* Ignore) on the command line. Request for NEW environment variable
* came from Richard Hallowell. Also added /DO option to include
* directories ONLY in the listing (no regular files are included).
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include <io.h>
#include "pdefs.h"
struct packed_date {
unsigned da : 5;
unsigned mo : 4;
unsigned yr : 7;
};
struct packed_time {
unsigned ss : 5;
unsigned mm : 6;
unsigned hh : 5;
};
#define PACKED_DATE(d) (*(struct packed_date *)(&(d)))
#define PACKED_TIME(t) (*(struct packed_time *)(&(t)))
typedef struct node NODE, *NODEPTR;
struct node {
struct find_t finfo;
char path[80];
NODEPTR next;
};
/* "modes" for parse() function */
#define CMDLINE 0
#define ENVIRON 1
char *syntax[] = {
"The syntax is: NEW [filespec [filespec...]] [options]\n",
"Options and filespec can be in any order. Valid options are:\n",
" /h Show this help screen",
" /? Same as /h",
" /n Show files SINCE the number of days specified by n",
" /-n Show files BEFORE the number of days specified by n",
" /p Pause when screen display is full",
" /s Search specified directory and its subdirectories",
" /e Search entire disk",
" /d Include directories in listing",
" /do Include directories ONLY in listing",
" /j Junk option -- include files with corrupted dates",
" /i Ignore the environment variable NEW if it is defined\n",
"If filespec is omitted, *.* is assumed. Also, a \"day\" in this "
"program",
"starts at 6:00 am and ends at 5:59 am the following day.", 0
};
char *cdow[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday" };
/* global variables */
int before = NO;
int pausing = NO;
int entire = NO;
int subdirs = NO;
int junk = NO;
int dirs = NO;
int ignore = NO;
int dirsonly = NO;
size_t hits = 0;
int lines = 3;
long since = 1L;
long jul, tjul; /* jul = date to check for, tjul = today's date */
NODEPTR filehead = NULL;
NODEPTR filetail = NULL;
NODEPTR spechead = NULL;
NODEPTR spectail = NULL;
NODEPTR *larray;
char hitfile[256];
char findspec[256];
int numrows; /* number of text rows */
/* function prototypes */
void parse(char *, int, int);
void print_syntax(void);
long gtoj(int, int, int);
void jtog(long, int *, int *, int *);
int dow(long);
NODEPTR addlist(struct find_t, char *, NODEPTR *, NODEPTR *);
int compare();
void display(void);
void check_pause(void);
void search(char *, char *);
main(int argc, char **argv)
{
int month, day, year, hours, i, option, len;
char *ptr, *p, *q, fullpath[128], basepath[128], filespec[13];
char environ[128], envarg[128];
struct dosdate_t date;
struct dostime_t time;
NODEPTR n;
struct find_t dummy;
/* Determine the number of text rows by looking at 0040:0084h */
numrows = (int)(*(char far *)0x00400084);
if (numrows == 0)
numrows = 24;
/* Could also have used INT 10h, function 1130h, which returns the
* number of rows (minus 1) in DL
*/
fprintf(stderr, "NEW V1.7 by Scott R. Houck\n");
while (--argc)
{
option = (**++argv == '/');
ptr = strtok(*argv, "/");
parse(ptr, option, CMDLINE);
while (ptr = strtok(NULL, "/"))
parse(ptr, 1, CMDLINE);
}
/* Check the environment for NEW options/filespecs */
if (!ignore && (p = getenv("NEW")) != NULL)
{
strcpy(environ, p);
p = environ;
while (*p)
{
/* strip off whitespace */
while (isspace(*p))
p++;
/* scan for whitespace */
for (q = p; *q && !isspace(*q); q++)
;
if (*q)
{
strncpy(envarg, p, q-p);
*q = EOS;
p = q + 1;
}
else
{
strcpy(envarg, p);
p = q;
}
option = (*envarg == '/');
ptr = strtok(envarg, "/");
parse(ptr, option, ENVIRON);
while (ptr = strtok(NULL, "/"))
parse(ptr, 1, ENVIRON);
}
}
if (!spechead)
addlist(dummy, "*.*", &spechead, &spectail);
_dos_getdate(&date);
_dos_gettime(&time);
if (time.hour >= 6)
--since;
tjul = gtoj(date.month, date.day, date.year);
jul = tjul - since;
jtog(jul, &month, &day, &year);
printf("Directory %s 6 am %s, %d-%02d-%02d\n\n",
before ? "before" : "since",
cdow[dow(jul)], month, day, year % 100);
if (subdirs || entire)
if (!isatty(fileno(stdout)))
fprintf(stderr, "\n");
for (n = spechead; n; n = n->next)
{
strupr(strcpy(filespec, n->path));
drfullpath(fullpath, 0, filespec); /* PforCe */
if (strchr(fullpath, '*') == NULL && strchr(fullpath, '?') == NULL)
{
if (fullpath[strlen(fullpath)-1] == '\\')
strcat(fullpath, "*.*");
else
strcat(fullpath, "\\*.*");
}
p = strrchr(fullpath, '\\');
len = p - fullpath + 1;
strncpy(basepath, fullpath, len);
basepath[len] = EOS;
strcpy(filespec, p+1);
if (entire)
{
subdirs = YES;
basepath[3] = EOS;
fullpath[2] = EOS;
strcat(fullpath, filespec);
}
if (subdirs)
vidcsrtyp(CSR_HIDDEN); /* PforCe */
search(basepath, filespec);
if (subdirs)
{
fprintf(stderr, "%-79s\r", "");
vidcsrtyp(CSR_NORMAL); /* P